import Libray.BookShelf;
import Opter.*;
import User.NormalUser;
import User.AdministorUser;
import User.User;
import java.util.Scanner;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: xwl
 * Date: 2023-04-15
 * Time: 23:16
 */
public class Main {
    // 创建用户方法
    private User setUser(int ret){

        if (ret == 1) {
            return new NormalUser();
        } else {
            // 返回管理员用户--待写
            return new AdministorUser();
        }
    }
    // 创建操作方法
    private void make(int choice,BookShelf bookShelf) {
        // 实例化操作
        QuestionOpter questionOpter = new QuestionOpter();
        LendOpter lendOpter = new LendOpter();
        ReturnOpter returnOpter = new ReturnOpter();
        ExitOpter exitOpter = new ExitOpter();
        // 输入
        Scanner scan = new Scanner(System.in);
        IOpter[] iOpter1 = new IOpter[]{questionOpter,lendOpter,returnOpter,exitOpter};
        if (choice == 0) {
            iOpter1[3].opterFun(bookShelf,"0");
        }
        String name = scan.nextLine();
        // 判断
        if (choice == 1) {
            iOpter1[0].opterFun(bookShelf,name);
        } else if (choice == 2) {
            iOpter1[1].opterFun(bookShelf,name);
        } else if (choice == 3) {
            iOpter1[2].opterFun(bookShelf,name);
        } else {
            System.out.println("输入错误，请重新输入");
        }
    }
    // 重写操作方法
    private void make(int choice,BookShelf bookShelf,boolean flag) {
        // 实例化操作
        QuestionOpter questionOpter = new QuestionOpter();
        AddOpter addOpter = new AddOpter();
        DeleteOpter deleteOpter = new DeleteOpter();
        ExitOpter exitOpter = new ExitOpter();
        ShowOpter showOpter = new ShowOpter();
        // 输入
        Scanner scan = new Scanner(System.in);
        IOpter[] iOpter1 = new IOpter[]{questionOpter,addOpter,deleteOpter,exitOpter,showOpter};
        String name;
        if (choice == 1 || choice == 3) {
            name = scan.nextLine();
        } else {
            name = "0";
        }
        // 判断
        if (choice == 1) {
            iOpter1[0].opterFun(bookShelf,name);
        } else if (choice == 2) {
            iOpter1[1].opterFun(bookShelf,name);
        } else if (choice == 3) {
            iOpter1[2].opterFun(bookShelf,name);
        } else if (choice == 0) {
            iOpter1[3].opterFun(bookShelf,name);
        } else if (choice == 4) {
            iOpter1[4].opterFun(bookShelf,name);
        }  else {
            System.out.println("输入错误，请重新输入");
        }
    }
    public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);
        // 实例化当前类对象
        Main test = new Main();
        System.out.println();
        // 输入用户权限
        System.out.println("请选择用户权限：");
        System.out.println("0、管理员用户");
        System.out.println("1、普通用户");
        // 创建相应用户对象
        User user = test.setUser(scan.nextInt());
        // 输入用户名
        System.out.println("请输入用户名：");
        user.setName(scan.next());
        //
        BookShelf bookShelf = new BookShelf();
        // 调用操作菜单
        while(true) {
            // 输入
            int choice = scan.nextInt();
            // 实现操作方法
            if (user instanceof NormalUser) {
                test.make(choice,bookShelf);
            } else {
                test.make(choice,bookShelf,true);
                System.out.println(bookShelf.getBookNum());
            }
        }
    }
}
